<%@ include file="../common.jsp"%>

<script type="text/javascript">
	$(document).ready(
			
			function() {
				$("#documentSubCategory").attr("action",'<c:url value="/saveDocSubCategoryNewDetails.htm"></c:url>');
				$("#docType").val('<c:out value="${docType}"></c:out>');
				$("#docCat").val('<c:out value="${docCat}"></c:out>');
				loadOnChangeMethods();
			});
</script>


<c:choose>
	<c:when test="${size eq 0}">
		No Records Found.
	</c:when>
	<c:otherwise>
		<div style="width: 70%;">
			<form name="submitSubCategToEdit" id="submitSubCategToEdit">
				<table class="viewDetails">
					<c:choose>
						<c:when test="${fn:contains(docCatSubCatMap, 'null')}">
							<tr class="message">
								<td colspan="4"> No Records Found. </td>
							</tr>
						</c:when>
						<c:otherwise>
							<tr class="adminTableMainHeaderColor tableChildHeaderFont">
								<th colspan="5" align="center"><span class="searchResultsCaption" > VIEW DOCUMENT SUB CATEGORY </span></th>
							</tr>
							<tr class="even"> 
								<td colspan="5">
										  Filters- &nbsp;&nbsp;&nbsp;&nbsp;  
										  		Type: <select id="docType" onchange="loadCategoryForEditSubCateg();">
															<option value="0">ALL</option>
															<c:forEach items="${docTypeMap1}" var="item">
																<option value="${item.key}">${item.value}</option>
															</c:forEach>
														 </select>
														
											   Category: <select id="docCat" onchange="filterSubCategList();">
											   				<option value="0">ALL</option>
											   				<c:forEach items="${docTypeMap}" var="item">
											   					<c:if test="${item.key eq docType }">
											   						<c:forEach items="${docTypeCatMap}" var="docCategory">
											   							<c:if test="${docCategory.key eq item.key }">
											   								<c:forEach items="${docCategory.value}" var="item2">
											   									<option value="${item2.dcId}">${item2.dcName}</option>	
											   								</c:forEach>
											   							</c:if>
																		
																	</c:forEach>	
											   					</c:if>
											   				</c:forEach>
															
									 					  </select>
								</td> 
							</tr>
							<tr class="heading">
								<th> Select </th>
								<th> Code </th>
								<th> SubCategory </th>
								<th> Category </th>
								<th> Type </th>
							</tr>	
						
							<c:forEach var="docTypeMap" items="${docTypeMap}" varStatus="index" >
								<c:forEach items="${docTypeCatMap[docTypeMap.key]}" var="docCategory">
									<c:forEach items="${docCatSubCatMap[docCategory.dcId]}" var="docSubCategory">
										<c:set var="tabColor" value="even"></c:set>
									     	<c:if test="${(index.index % 3) eq 0}">
									        	<c:set var="tabColor" value="odd"></c:set>
									        </c:if> 
									    <tr class="${tabColor}">   
									    	<td align="center"> <input type="radio" id="radio${index.index}" name="myradio" value="${docSubCategory.dscId},${docSubCategory.dscName},${docTypeMap.key},${docCategory.dcId},${docSubCategory.dscCode}"/> </td>
											<td> ${docSubCategory.dscCode} </td>
											<td> ${docSubCategory.dscName} </td>
											<td> ${docCategory.dcName} </td>
											<td> ${docTypeMap.value} </td>
										</tr>
									</c:forEach>
								</c:forEach>
							</c:forEach>
							<table>
								<tr align="left">
									<td colspan="5">
										<input class="formButton ui-corner-all" type="button" value="SELECT" onclick="submitSubCategDetailsForEditing();" />
									</td>
								</tr>
							</table>
						</c:otherwise>
					</c:choose>
				</table>
				
			</form>
		</div>
		
		<c:if test="${resultOfSave}">
			Operation Done Successfully.
		</c:if>
		
		<br>
		<hr/>
		<br>
		
		<form:form commandName="documentSubCategory" id="documentSubCategory">
						<form:hidden path="dscId" id="dscId"/>
			<table class="adminFilterTable">
				<tr class="tableChildHeaderColor">
					<th colspan="5" align="center"> EDIT DOCUMENT SUB CATEGORY </th>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr> 
					<td align="left" colspan="5" style="font-family: verdana; font-size: 12px;"> All fields are mandatory.</td> 
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> SubCategory* </td>
					<td class="spacingColumnWidthLess"></td>	
					<td class="formField"> <form:input path="dscName" id="dscName"/> 
						<form:errors path="dscName" cssClass="errorMsg" /> </td>
					<td class="spacingColumnWidthLess"></td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> Code* </td>
					<td class="spacingColumnWidthLess"></td>	
					<td class="formField"> <form:input readonly="true" path="dscCode" id="dscCode"/> 
						<form:errors path="dscCode" cssClass="errorMsg" /> </td>
					<td class="spacingColumnWidthLess"></td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> Document Type* </td>
					<td class="spacingColumnWidthLess"></td>
					<td class="formField"> 
						<form:select path="dscParentCategory.dcParentType.dtId" id="docTypeID">
							<form:option value="0">Choose Type</form:option>
							<c:forEach items="${docTypeMap1}" var="docTypeMap">
								<form:option value="${docTypeMap.key}">${docTypeMap.value}</form:option>
							</c:forEach>
						</form:select>
						<form:errors path="dscParentCategory.dcParentType.dtId" /> </td>
					<td class="spacingColumnWidthLess"></td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>
				<tr>
					<td class="spacingColumnWidthLess"></td>
					<td class="formLabel"> Document Category </td>	
					<td class="spacingColumnWidthLess"></td>
					<td class="formField"> 
						<form:select path="dscParentCategory.dcId" id="docCatID" >
							<form:option value="0">Choose Category</form:option>
							<c:forEach items="${docTypeMap}" var="item">
									<c:forEach items="${docTypeCatMap}" var="docCategory">
										<c:if test="${docCategory.key eq item.key }">
											<c:forEach items="${docCategory.value}" var="item2">
												<option value="${item2.dcId}">${item2.dcName}</option>
											</c:forEach>
										</c:if>
									</c:forEach>
							</c:forEach>
						</form:select>
					</td>
					<td class="spacingColumnWidthLess"></td>
				</tr>	
				<tr class="formSpacingRow"><td></td> </tr>
				<tr align="left">
					<td class="spacingColumnWidthLess"></td>
					<td></td>
					<td class="spacingColumnWidthLess"></td>
					<td colspan="2">
						<input class="formButton ui-corner-all" type="button" value="UPDATE" onclick="javascript:addEntity('documentSubCategory')">
					</td>
				</tr>
				<tr class="formSpacingRow"><td></td> </tr>			
			</table>
		</form:form>
	</c:otherwise>
</c:choose>
